<template>
  <el-container class="home_container">
    <!-- 头部区域 -->
    <el-header>
      <div class="header_left">
        <div class="headerBrea">
          后台管理
        </div>
      </div>
      <div class="header_right">
        <span>{{ dateTime }}</span>
        <!-- <span>当前账号：1590444</span> -->
        <el-button type="info" size="small" @click="editHandle">退出</el-button>
      </div>
    </el-header>
    <el-container>
      <el-aside>
        <div :class="activePath == '/homePage' ? 'activeBox ConsoleBox' : 'ConsoleBox'"
          @click="navClick('/homePage', 0)" v-if="companyId == 1 && loginType == 1"> <i class="el-icon-s-operation"
            style="margin-right: 10px;"></i>控制台</div>
        <el-menu :default-active="activePath" background-color="#293849" text-color="#fff" active-text-color="#ffd04b"
          unique-opened router>
          <!-- 一级菜单 -->
          <el-submenu :index="item.menuUrl" v-for="(item, index) in menulist" :key="index">
            <template slot="title">
              <i :class="item.icon" style="margin-right: 10px;"></i>
              <span>{{ item.menuName }}</span>
            </template>
            <el-menu-item :index="ele.menuUrl" v-for="(ele, eIndex) in item.children" :key="eIndex"
              @click="navClick(ele, 1)">
              <template slot="title">
                <i :class="ele.icon" style="margin-right: 10px;"></i>
                <span>{{ ele.menuName }}</span>
              </template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <!-- 主体区域 -->
      <el-main>
        <div class="content">
          <router-view></router-view>
          <!-- <keep-alive>
            <router-view></router-view>
          </keep-alive> -->
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
export default {
  name: 'HomeR',
  data() {
    return {
      // 时间
      dateTime: '',
      userName: "",
      // 侧边菜单是否折叠
      isCollapse: false,
      //   左侧菜单数据
      menulist: JSON.parse(sessionStorage.menulist),
      pathName: '',
      //   激活的链接地址
      activePath: sessionStorage.activePath,
      companyId: sessionStorage.companyId,
      loginType: sessionStorage.loginType
    }
  },
  mounted() { },
  methods: {
    navClick(item, flag) {
      var url = flag == 1 ? item.menuUrl : item
      window.sessionStorage.setItem('activePath', url)
      this.activePath = url
      if (flag == 0) {
        this.$router.push(url)
      }
      this.$forceUpdate()
    },

    // 退出按钮  通过清空本地 token 和 编程式路由跳转到 /login  实现退出功能
    editHandle() {
      this.$confirm('是否退出登录?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        window.localStorage.clear()
        sessionStorage.clear()
        this.$router.replace('/login')
      }).catch(() => {
        this.$message.warning('已取消退出')
      });
    },
    // 保持菜单链接处于激活状态
    saveNavState(activePath) {
      window.sessionStorage.setItem('activePath', activePath)
      console.log(activePath)
    },
    // 获取当前时间
    getNowDate() {
      var myDate = new Date;
      var year = myDate.getFullYear();
      var mon = myDate.getMonth() + 1;
      mon = mon < 10 ? '0' + mon : mon
      var date = myDate.getDate();
      date = date < 10 ? '0' + date : date
      var date1 = myDate.getDate() + 1;
      date1 = date1 < 10 ? '0' + date1 : date1
      var hours = myDate.getHours();
      hours = hours < 10 ? '0' + hours : hours
      var minutes = myDate.getMinutes();
      minutes = minutes < 10 ? '0' + minutes : minutes
      var seconds = myDate.getSeconds();
      seconds = seconds < 10 ? '0' + seconds : seconds
      return year + "年" + mon + "月" + date + "日"
    }
  },
  created() {
    // 获取激活的链接的地址
    this.activePath = window.sessionStorage.getItem('activePath')
    this.dateTime = this.getNowDate()
  },
}
</script>

<style lang='less' scoped>
// 容器
.home_container {
  height: 100vh;

  // 头部区域样式
  .el-header {
    padding-left: 0px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 60px !important;
    background: #304155;
    box-shadow: 0px 1px 7px 1px rgba(94, 94, 95, 0.11);
    border-radius: 5px 5px 0px 0px;

    .header_left {
      display: flex;
      align-items: center;
      cursor: pointer;

      .headerBrea {
        box-sizing: border-box;
        width: 200px;
        height: 60px;
        line-height: 60px;
        text-align: center;
        background: #293849;
        font-size: 20px;
        font-family: Source Han Sans CN;
        font-weight: bold;
        color: #FFFFFF;
      }

      span {
        margin-left: 30px;
        font-size: 20px !important;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #FFFFFF;
      }
    }

    .header_right {
      display: flex;
      align-items: center;
      cursor: pointer;

      span {
        margin-right: 20px;
        font-size: 16px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #FFFFFF;
      }
    }
  }

  // 侧边栏区域
  .el-aside {
    width: 200px !important;
    box-sizing: border-box;
    // padding-top: 20px;
    // padding-left: 15px;
    // background-color: #fff;
    background-color: #293849;

    // 解决菜单栏展开右侧的边框线
    .el-menu {
      border-right: none;
    }
  }

  // 主体区域
  .el-main {
    padding: 0px !important;
    background-color: #F3F5F7;
  }
}

// 字体图标样式
.iconfont {
  margin-right: 10px;
}




// .el-menu-item {
//   margin-bottom: 9px;
//   width: 124px;
//   height: 47px;
//   line-height: 47px;
//   border-radius: 6px;
//   font-size: 16px;
//   font-family: Microsoft YaHei;
//   font-weight: bold;
//   color: #68728E;
// }

//子节点鼠标移入样式
// .el-menu-item:hover,
// .el-submenu:hover {
//   background-color: RGBA(52, 137, 255, 0.3) !important;
//   border-radius: 6px;
//   // font-size: 16px;
//   font-family: Microsoft YaHei;
//   font-weight: bold !important;
//   color: #fff !important;
//   i {
//     color: #fff;
//   }
// }
// 子节点鼠标移入样式
// .el-menu-item:hover,
// .el-submenu:hover {
//   background-color: RGBA(52, 137, 255, 0.3) !important;
//   // border-radius: 6px;
//   // font-size: 16px;
//   font-family: Microsoft YaHei;
//   // font-weight: bold !important;
//   // color: #fff !important;
//   i {
//     color: #fff;
//   }
// }

.content {
  box-sizing: border-box;
  padding: 15px;
  width: 100%;
  height: 90vh;
  overflow-y: scroll;
  border-radius: 10px;
  padding-bottom: 15px;
}

.ConsoleBox {
  box-sizing: border-box;
  padding: 0 20px;
  display: flex;
  align-items: center;
  // justify-content: center;
  width: 200px;
  height: 56px;
  font-size: 14px;
  color: #fff;
  cursor: pointer;
}

.ConsoleBox>i {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.activeBox {
  color: rgb(255, 208, 75) !important;
}
</style>